<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>获取dom节点</title>
</head>

<body>
    <div id="app">
        <input type="button" value="按钮" id="btn" @click="getDom" ref="mybtn" />
        <h2 ref="box" id="box">{{msg}}</h2>
    </div>
</body>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<script>
    // 1、传统方式
    // document.getElementById("btn").onclick = function () {
    //   console.log(this.value)
    // }

    var vm = new Vue({
        el: "#app",
        data: {
            msg: "默认数据"
        },
        methods: {
            getDom() {
                console.log(this)
                console.log(this.$refs)
                console.log(this.$refs.mybtn)

                // 获取dom节点的值
                console.log(document.getElementById("box").innerText)
                console.log(this.$refs.box.innerText)
            }
        }
    })
</script>

</html>